﻿@model SMECustomerWebsite.Models.ViewModels.SalePerformance.DepositViewModel
@Html.Action("SubMenuKpi", "System")
<div class="row">
    <div class="col-md-12">
        <div class="x_panel">
            <div class="x_title">
                @if (Model.DaoInfo.Dao != "khong co DAO" && !string.IsNullOrEmpty(Model.Dao))
                {
                    <h2>Kết quả KPI của @Model.DaoInfo.FullName <a data-toggle="modal" data-target=".sp-dao-info" style="font-size:14px;"> <i class="fa fa-info-circle"></i> </a></h2>
                }
                else
                {
                    <h2>@SMECustomerWebsite.Core.Resources.Resource.NotChooseMsboSalePerformance</h2>
                }
                <ul class="nav navbar-right panel_toolbox">
                    @Html.Action("BusinessDateInfo", "System", new { name = "TBL_KPI_MSBO_RAW" })
                    <li>
                        <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <div class="title_right cm-search-box col-md-12 ">
                    <div id="cp-search-box" class="col-md-3 cm-search-box">
                        @if (Model.DaoInfo.GroupIdentifier != "4")
                        {
                            <div class="col-md-12">
                                <select id="sp-deposit-msbo-dropdown" class="search_column form-control" tabindex="-1">
                                    <option></option>
                                </select>
                            </div>
                        }
                    </div>
                </div>
                <table id="sp-deposit" class="table table-bordered table-striped jambo_table custom_table" style="width:100% !important">
                    <thead class="headings">
                        <tr>
                            <th class="column-title">Nhóm chỉ tiêu</th>
                            <th class="column-title">STT</th>
                            <th class="column-title">Tên chỉ tiêu</th>
                            <th class="column-title">Đơn vị đo</th>
                            <th class="column-title">Trọng số (%)</th>
                            <th class="column-title">KH tháng @DateTime.Now.Month</th>
                            <th class="column-title">KQ tháng @DateTime.Now.Month</th>
                            <th class="column-title">% tháng @DateTime.Now.Month</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>
</div>

@section scripts
{
    <script src="~/Scripts/tableeditable/dataTables.rowsGroup.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                url: '/MSBO/ListMSBOName',
                type: "POST",
                data: { data: 1 },
                success: function (data_response) {

                    $("#sp-deposit-msbo-dropdown").select2({
                        placeholder: "Select MSBO",
                        data: data_response
                    });
                    $("#sp-deposit-msbo-dropdown").val("@Model.Dao").trigger("change");
                    $("#sp-deposit-msbo-dropdown").on("change", function (e) {
                        msboselected = $("#sp-deposit-msbo-dropdown").val();
                        var link = "@Url.Action("KPIs", "SalePerformance", new { dao=-1})";
                        link = link.replace("-1", msboselected);
                        window.location.replace(link);
                    });
                }
            });
            var table = $('#sp-deposit').DataTable({
                bFilter: false,
                bInfo: false,
                bPaginate: false,
                "responsive": true,
                "bAutoWidth": true,
                "order": [[0, 'asc']],
                "bServerSide": true,
                rowsGroup: [0],
                //"bProcessing": true,
                "sAjaxSource": '@Url.Action("KPIData", "SalePerformance")' + '?dao=@Model.Dao',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "aoColumns": [
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "className": 'column-title', "bSortable": false },
                            { "sName": "DATE OPEN", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                            { "sName": "DATE OPEN", "className": 'column-title', "bSortable": false },
                            { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                            { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                            { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false }],
                "aoColumnDefs": [{
                    "aTargets": [6],
                    "mRender": function (data, type, full) {
                        if (full[8] == '') {
                            return data;
                        } else {
                            return '<a href="' + full[8] + '?dao=@Model.Dao" style="color:red;">' + data + ' <i class="fa fa-book"></i></a>';
                        }
                    }
                }],
                "drawCallback": function (settings) {
                    $('table.custom_table th').removeClass().addClass('column-title');
                }
            });

        });
    </script>
}